package com.example.administrator.myapplication.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/18 0018.
 */
public abstract class SimpleBaseAdapter<T> extends BaseAdapter {
    private List<T> dataList = new ArrayList<T>();

    protected LayoutInflater mInflater;
    public SimpleBaseAdapter(Context context)
    {
        mInflater = LayoutInflater.from(context);
    }

    //提供添加数据的方法
    public void addData(T t)
    {
        dataList.add(t);
    }
    public void addData(List<T> list)
    {
        dataList.addAll(list);
    }

    //提供先清空再添加的方法
    public void setData(T t)
    {
        dataList.clear();
        dataList.add(t);
    }
    public void setData(List<T> list)
    {
        dataList.clear();
        dataList.addAll(list);
    }

    //返回所有数据
    public List<T> getDataList()
    {
        return dataList;
    }

    @Override
    public int getCount()
    {
        return dataList.size();
    }

    @Override
    public T getItem(int position)
    {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        return getItemView(position, convertView, parent);
    }

    public abstract View getItemView(int position, View convertView, ViewGroup parent);
}
